﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Shop.Core.Data.Orders;
using Shop.Core.Domain.Orders;
using System.Collections;
using Shop.Core.Data.Customers;
using Shop.Core.Domain.Customers;

namespace Shop.Data.IBatis.Customers
{
    public class CustomerRepository : DaoBase, ICustomerRepository
    {
        /// <summary>
        /// 获取订单
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Customer GetById(int id)
        {
            return this.Reader.QueryForObject<Customer>(this.GetCustomerSM("SelectByIdList"), id.ToString());
        }

        /// <summary>
        /// 插入用户信息
        /// </summary>
        /// <param name="entity"></param>
        public bool Insert(Customer entity)
        {
            this.Writer.Insert(this.GetCustomerSM("Insert"), entity);
            return true;
        }

        /// <summary>
        /// 逻辑删除用户
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public bool Delete(Customer entity)
        {
            return this.Writer.Update(this.GetCustomerSM("DeleteCustomer"), entity) == 1;
        }

        /// <summary>
        /// 批量查询用户
        /// </summary>
        /// <param name="idList"></param>
        /// <returns></returns>
        public IList<Customer> FindByIdList(IList<int> idList)
        {
            string ids = string.Join(",", idList);
            return this.Reader.QueryForList<Customer>(this.GetCustomerSM("SelectByIdList"), ids);
        }

        public bool Update(Customer entity)
        {
            throw new NotImplementedException();
        }

        public Customer GetCustomerByEmail(string email)
        {
            return this.Reader.QueryForObject<Customer>(this.GetCustomerSM("GetCustomerByEmail"), email);
        }

        public Customer GetCustomerByNickName(string nickName)
        {
            return this.Reader.QueryForObject<Customer>(this.GetCustomerSM("GetCustomerByNickName"), nickName);
        }

        protected virtual string GetCustomerSM(string id)
        {
            return string.Format("Shop.Customer.{0}", id);
        }
    }
}
